package com.yaglyf.mvc.aop.impl;

import com.yaglyf.mvc.aop.annotation.Auth;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

/**
 * Title: Class CommentsShow
 * Description:
 * 注释展示类，说明各种方法注释怎么写
 *
 * @author qiang.yang
 * @email qiang.yang@chinaredstar.com
 * @version 1.0.0
 * @date: 2016/10/10 13:49
 */
@Aspect
@Component
public class ExceptionManage {

    @Autowired
    private HttpServletRequest request;

    @Pointcut("@within(com.yaglyf.mvc.aop.annotation.ExceptionHandler)")
    public void exception(){

    }

    @Around("exception()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {

//        String className = pjp.getTarget().getClass().getSimpleName();
        Class<?> clazz = pjp.getTarget().getClass();
        Object[] args = pjp.getArgs();
        for (Object o : args){
            if (null == o){
//                return
            }
        }

        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        Auth auth = method.getAnnotation(Auth.class);

        String base = clazz.getSimpleName()+method.getName();


        String  uri = request.getRequestURI();
        Object o = null;
        try {
            o = pjp.proceed();
        }catch (Exception e){

        }



        return o;
    }


}
